package com.tedu.openmedical.duplicate.medical_duplicate.controller;

import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.dto.MailInfoParam;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.dto.TableSelectParam;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.dto.InsertRecordParam;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.dto.UpdateRecordParam;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.vo.RecordDetailVO;
import com.tedu.openmedical.duplicate.medical_duplicate.pojo.vo.RecordTableVO;
import com.tedu.openmedical.duplicate.medical_duplicate.service.MedicalDuplicateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "复印申请管理")
@Slf4j
@RestController
@RequestMapping("/v1/duplicate/medical_duplicate/")
public class MedicalDuplicateController {
    @Autowired
    private MedicalDuplicateService service;

    @ApiOperation(value = "获取申请列表表格数据")
    @GetMapping("select")
    public JsonResult loadTableData(TableSelectParam param){
        log.debug("获取申请列表表格数据，param:{}",param);
        List<RecordTableVO> list = service.loadTableData(param);
        return JsonResult.ok(list);
    }

    @ApiOperation("新增申请")
    @PostMapping("insert")
    public JsonResult insertDuplicate(InsertRecordParam param){
        log.debug("新增申请，param:{}",param);
        service.insertDuplicate(param);
        return JsonResult.ok();
    }

    @ApiOperation("更新申请状态")
    @PostMapping("update")
    public JsonResult updateDuplicate(UpdateRecordParam param){
        log.debug("更新申请，param:{}",param);
        service.updateDuplicate(param);
        return JsonResult.ok();
    }

    @ApiOperation(value = "获取详细数据")
    @GetMapping("select_detail/{id}")
    public JsonResult loadDetail(@PathVariable("id") Long id){
        log.debug("获取申请详细数据，id:{}",id);
        RecordDetailVO detail = service.loadDetail(id);
        log.debug("成功获取数据，detail:{}",detail);
        return JsonResult.ok(detail);
    }

    @ApiOperation(value = "新增邮寄单")
    @PostMapping("insert_mail")
    public JsonResult insertMailInfo(MailInfoParam param){
        log.debug("新增邮寄单信息，param:{}",param);
        service.insertMailInfo(param);
        return JsonResult.ok();
    }
}
